package com.ssm.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ssm.entity.Book;
import com.ssm.mapper.BookMapper;
import com.ssm.service.BookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class BookServiceImpl  implements BookService {
    @Autowired
    private BookMapper bookMapper;
    @Override
    public List<Book> findAll() {

        return bookMapper.selectAll();
    }

    @Override
    public Book findById(Integer id) {
        return bookMapper.selectById(id);
    }

    @Override
    public boolean save(Book book) {
         bookMapper.insert(book);
         return true;
    }

    @Override
    public boolean update(Book book) {
        bookMapper.update(book);
        return true;
    }

    @Override
    public boolean deleteById(Integer id) {
        bookMapper.deleteById(id);
        return true;
    }

    public PageInfo<Book> findPaged(int pageNum, int pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<Book> list = bookMapper.selectAll();
        return new PageInfo<>(list);
    }

    @Override
    public boolean batchDelete(List<Integer> ids) {
        bookMapper.batchDelete(ids);
        return true;
    }

}
